package com.huilian.iotbox.admin.service.impl;

import com.huilian.iotbox.admin.dao.StatsUserDeviceTypeDao;
import com.huilian.iotbox.admin.service.StatsUserDeviceTypeService;
import com.huilian.iotbox.data.dto.StatsUserDeviceTypeDto;
import com.huilian.iotbox.data.po.StatsUserDeviceType;
import com.huilian.iotbox.data.utils.DateTimeUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: loong
 * @create: 2023-04-19 15:15
 **/
@Service
public class StatsUserDeviceTypeServiceImpl implements StatsUserDeviceTypeService {
    @Resource
    private StatsUserDeviceTypeDao statsUserDeviceTypeDao;

    @Override
    public void statsYesterdayUserDeviceType() {
        StatsUserDeviceTypeDto statsDeviceUserDto = new StatsUserDeviceTypeDto();
        statsDeviceUserDto.setDateStr(DateTimeUtils.getYesterday());
        List<StatsUserDeviceType> statsUserDeviceTypes = statsUserDeviceTypeDao.statsUserDeviceType(statsDeviceUserDto);
        statsUserDeviceTypes.forEach(statsDeviceStore -> {
            statsDeviceStore.setType(1);
            statsDeviceStore.setDateStr(statsDeviceUserDto.getDateStr());
            statsUserDeviceTypeDao.add(statsDeviceStore);
        });
    }

    @Override
    public void statsMonthUserDeviceType() {
        StatsUserDeviceTypeDto statsDeviceUserDto = new StatsUserDeviceTypeDto();
        statsDeviceUserDto.setStartDateStr(DateTimeUtils.getPreviousMonthFirstDay());
        statsDeviceUserDto.setEndDateStr(DateTimeUtils.getPreviousMonthLastDay());
        List<StatsUserDeviceType> statsUserDeviceTypes = statsUserDeviceTypeDao.statsMonthUserDeviceType(statsDeviceUserDto);
        statsUserDeviceTypes.forEach(statsDeviceStore -> {
            statsDeviceStore.setType(2);
            statsDeviceStore.setDateStr(DateTimeUtils.getPreviousMonth());
            statsUserDeviceTypeDao.add(statsDeviceStore);
        });
    }
}
